﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;
using ww.form.lis.com;
using System.Collections;
using ww.lis.lisbll.sam;
using System.Data.SqlClient;
using ww.form.Properties;

namespace ww.form.lis.sam.jy
{

    public partial class PacsQueryForm : com.JyBaseForm
    {
        public DateTime StartTime { get; private set; }
        public DateTime EndTime { get; private set; }
        public string DepartmentID { get; private set; }
        public int HasApp { get; private set; }
        public int HasBD { get; private set; }
        public int HasExecuteing { get; private set; }
        public int HasFinish { get; private set; }
        public string PatientID { get; private set; }
        public string PatientName { get; private set; }
        public int HasYingx { get; private set; }
        public int HasYangx { get; private set; }
        public int HasYsh { get; private set; }
        public int HasWsh { get; private set; }

        public PacsQueryForm()
        {
            InitializeComponent();
        }

        private void bt_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_select_Click(object sender, EventArgs e)
        {
            this.StartTime = this.dtStartTime.Value;
            this.EndTime = this.dtEndTime.Value;
            this.DepartmentID = this.cbDepartment.SelectedValue != null ? this.cbDepartment.SelectedValue.ToString() : string.Empty;
            this.HasExecuteing = this.ckExe.Checked ? 1 : 0;
            this.HasFinish = this.ckFinish.Checked ? 1 : 0;
            this.PatientID = this.tb_PatientID.Text.Trim();
            this.PatientName = this.tb_PatientName.Text.Trim();
            this.HasYingx = this.ckyingx.Checked ? 1 : 0;
            this.HasYangx = this.ckyangx.Checked ? 1 : 0;
            this.HasYsh = this.ckysh.Checked ? 1 : 0;
            this.HasWsh = this.ckwsh.Checked ? 1 : 0;

            SqlConnection SqlConn = new SqlConnection(Settings.Default.PACS_Conn);
            try
            {
                if (SqlConn.State != ConnectionState.Open)
                    SqlConn.Open();
                SqlDataAdapter SqlDa = new SqlDataAdapter("exec p_查询检查结果信息 '" + StartTime + "','" + EndTime + "','" + DepartmentID
                    + "','" + HasExecuteing + "','" + HasFinish + "','" + PatientID + "','" + PatientName + "','" + HasYingx + "','"
                    + HasYangx + "','" + HasYsh + "','" + HasWsh + "'", SqlConn);
                DataTable dt = new DataTable();
                SqlDa.Fill(dt);

                this.dataGridViewReport.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SqlConn.Close();
            }

            for (int i = 0; i < this.dataGridViewReport.Columns.Count; i++)
            {
                this.dataGridViewReport.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
        }

        private void PacsQueryForm_Load(object sender, EventArgs e)
        {
            this.dtStartTime.Value = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));
            this.dtEndTime.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(1).AddSeconds(-1);

            SqlConnection SqlConn = new SqlConnection(Settings.Default.PACS_Conn);
            try
            {
                if (SqlConn.State != ConnectionState.Open)
                    SqlConn.Open();
                SqlDataAdapter SqlDa = new SqlDataAdapter("select * from 部门", SqlConn);
                DataTable dt = new DataTable();
                SqlDa.Fill(dt);

                cbDepartment.DataSource = dt;
                cbDepartment.ValueMember = "ID";
                cbDepartment.DisplayMember = "简称";
                cbDepartment.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SqlConn.Close();
            }
        }

        private void dataGridViewReport_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (object.Equals(null, dataGridViewReport.CurrentRow)) return;

            Clipboard.SetDataObject(dataGridViewReport.CurrentRow.Cells["备注"].Value);
        }
    }
}